module;
#include <list>
#include <algorithm>
#include <mutex>
#include <iostream>

export module Code_3_2_1;

std::list<int> some_list;
std::mutex some_mutex;         

void add_to_list(int new_value)
{
    std::scoped_lock guard(some_mutex);
    some_list.push_back(new_value);
}
bool list_contains(int value_to_find)
{
    std::scoped_lock guard(some_mutex);
    return std::find(some_list.begin(), some_list.end(), value_to_find)
        != some_list.end();
}

export
namespace Code_3_2_1 {

    void run_thread()
    {
        add_to_list(42);
        std::cout << "contains(1)=" << list_contains(1) << ", contains(42)=" << list_contains(42) << std::endl;
    }
}
